﻿using System;
using Kiva7.Utilities;
using Kiva7.DataResponse;
using Kiva7.DataClasses;

namespace Kiva7.DataRequests
{
    public class PartnersRequest : DataRequest<PartnersResponse, Partner>
    {
        public PartnersRequest()
            : base(true, true)
        {
        }

        public Uri BuildUri()
        {
            UrlCreator url = new UrlCreator(BaseUrl + "partners.xml");

            url.Add("app_id", KivaAppId);

            return url.ToUri();
        }

        public void GetPartner(int partnerId)
        {
            LoadResponse(BuildUri(), partnerId);
        }

        protected override void CopyResponse(PartnersResponse response)
        {
            base.CopyResponse(response);
            if (response != null
                && response.Partners != null
                && response.Partners.PartnerItems != null)
            {

                foreach (Partner partner in response.Partners.PartnerItems)
                {
                    Partners.Add(partner.Id, partner);
                }
            }
        }

        private readonly PartnerDictionary _partners = new PartnerDictionary();
        public PartnerDictionary Partners
        {
            get
            {
                return _partners;
            }
        }
    }
}
